package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.index.NoticeMapper;
import com.kuaimacode.kframework.mybatis.models.index.Notice;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author qinyong
 * @Title:
 * @Package com.kuaimacode.kframework.api.service
 * @Description: created by IntelliJ IDEA
 * @date 2019-03-15 22:32
 */
@Service
public class NoticeService extends ServiceImpl<NoticeMapper, Notice> {

    /**
     * 查询分站公告信息
     * @param agentId
     * @return
     */
    public List<Notice> getListByAgent(String agentId) {
        Date now = new Date();
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("begin_time", now)
                .gt("end_time", now);
        queryWrapper.eq("agent_id", agentId);

        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 获取分店的公告条数
     * @param agentId
     * @return
     */
    public Integer getCountByAgent(Integer agentId) {
        Date now = new Date();
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("agent_id", agentId)
                .le("begin_time", now)
                .gt("end_time", now);
        return baseMapper.selectCount(queryWrapper);
    }
}
